using Microsoft.AspNetCore.Mvc;
using ConsoleApi.Models;
using ConsoleApi.Services.Console;
using MESData.ErrorCode;

namespace ConsoleApi.Controllers
{
    /// <summary>
    /// 销售订单控制器
    /// </summary>
    [ApiController]
    [Route("api/[controller]")]
    public class ProductionSalesOrderController : ControllerBase
    {
        private readonly IConsoleService _consoleService;

        public ProductionSalesOrderController(IConsoleService consoleService)
        {
            _consoleService = consoleService;
        }

        /// <summary>
        /// 获取销售订单列表
        /// </summary>
        [HttpGet]
        public async Task<ApiResult<PagedResultDto<ProductionSalesOrderDto>>> GetProductionSalesOrders([FromQuery] ProductionSalesOrderQueryDto query)
        {
            return await _consoleService.GetProductionSalesOrdersAsync(query);
        }

        /// <summary>
        /// 获取销售订单详情
        /// </summary>
        [HttpGet("{id}")]
        public async Task<ApiResult<ProductionSalesOrderDto>> GetProductionSalesOrder(int id)
        {
            return await _consoleService.GetProductionSalesOrderAsync(id);
        }

        /// <summary>
        /// 创建销售订单
        /// </summary>
        [HttpPost]
        public async Task<ApiResult<ProductionSalesOrderDto>> CreateProductionSalesOrder([FromBody] ProductionSalesOrderDto dto)
        {
            return await _consoleService.CreateProductionSalesOrderAsync(dto);
        }

        /// <summary>
        /// 更新销售订单
        /// </summary>
        [HttpPut]
        public async Task<ApiResult<ProductionSalesOrderDto>> UpdateProductionSalesOrder([FromBody] ProductionSalesOrderDto dto)
        {
            return await _consoleService.UpdateProductionSalesOrderAsync(dto);
        }

        /// <summary>
        /// 删除销售订单
        /// </summary>
        [HttpDelete("{id}")]
        public async Task<ApiResult<bool>> DeleteProductionSalesOrder(int id)
        {
            return await _consoleService.DeleteProductionSalesOrderAsync(id);
        }
    }
} 